To create a category, you must implement it within an @implementation block, which is terminated by the @end directive. Place the category name in parentheses after the class name.
The following example is a simple category of WORequest that gets the sender's Internet e-mail address from the request headers ("From" key) and returns it (or "None").
@implementation WORequest(RequestUtilities)Elsewhere in your WebScript code, you invoke this method on WORequest objects just as you do with any other method of that class. Here's an example:
- emailAddressOfSender {
NSString *address = [self headerForKey:@"From"];
if (!address) address = @"None";
return address;
}
@end
- takeValuesFromRequest:request inContext:context {Note: If your category is at the end of a scripted component, you must restart your app each time you change that file.
[super takeValuesFromRequest:request inContext:context];
[self logWithFormat:@"Email address of sender: %@",
[request emailAddressOfSender]];
}
Table of Contents
Next Section